-- card: 15794 from stack: in.5 -- bmap block id: 16194 -- flags: 0000 -- background id: 3858 -- name: CurrAppPath ----- HyperTalk script ----- on HideObjects hide cd btn "Try It!" end HideObjects on ShowObjects show cd btn "Try It!" end ShowObjects -- part 1 (button) -- low flags: 00 -- high flags: A002 -- rect: left=82 top=185 right=219 bottom=175 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 8192 -- line height: 16 -- part name: Try it! ----- HyperTalk script ----- on mouseUp global errGlobal put HCPath("noDialog:errGlobal") into thePath if errGlobal ≠ empty then answer "Error: “" & errGlobal & "”" put empty into errGlobal else answer "This copy of HyperCard is located: “" & thePath & "”" end if end mouseUp -- part contents for background part 38 ----- text ----- 8/50 -- part contents for background part 20 ----- text ----- CurrAppPath - This XFCN returns the full path name of the current application - HyperCard in the case of this stack. When running under Mac OS the correct path is reported even when you move the application around between calls to the XFCN. Under A/UX 2.0 this is not always the case. It occasionally seems to take a while for the file manager to be informed that a file has moved. Will this cause you trouble? Only if you launch an application, go to the finder or CommandShell, move the application, and then quickly go back and call the XFCN. Even then you will just get the old path, not the end of the world? CurrAppPath( «"noDialog:"errorGlobal») -- part contents for background part 42 ----- text ----- { CurrAppPath(<“noDialog”:errorGlobal>) } { XFCN returns fullpath to the current application } {} { brought to you by: Anup Murarka Eric Carlson } { ALINK: SKEPTIC ALINK: cyNic } { CIS: 76004,3356 } {} { We are part of the Support Tools Development Group, } { Apple Computer, Inc. } {} { please DO NOT contack Mac DTS for support of this code! } {} { please DO contact the authors for support of this code! } {} { Send comments, bug reports, requests to any of the above } { E-mail addresses or to:} {} { (one of us) } { Apple Computer, Inc. } { 900 E. Hamilton, Ave. } { Campbell, CA 95008 } { M/S 72-L } {} { Copyright: © 1989, 1990 by Apple Computer, Inc., all rights reserved. } {} { written by Eric Carlson } { AppleLink: cyNic } { modification history } { Date Initials Comments } { ---- ------ ------------------------------------------------------} { 7/23/90 ec first written } { 8/28/90 ec/akm removed code which disposed handle returned from } { GetAppParms (NOT a good thing to do!), was causing occasional} { crashes. set FP.ioVRefNum INSIDE of loop so can look past } { default volume. } {} unit CurrAppPath; interface uses HyperXCMD; procedure MAIN (paramPtr: XCmdPtr); implementation procedure reportToUser (paramPtr: XCmdPtr; msgStr: str255); {} { report something back to the user. } { the last parameter (optional) to an external may contain } { "noDialog" or "noDialog:GlobalName". GlobalName is the name } { of a HyperTalk global variable into which error messages will be } { placed. we've decided to use this approach to avoid confusing } { an error message with a valid result being returned from an XFCN. } {} var tempStr: str255; begin {check the last param to see if the user requested that} { we suppress the error dialog } ZeroToPas(paramPtr, paramPtr^.params[paramPtr^.paramCount]^, tempStr); UprString(tempStr, true); if pos('NODIALOG', tempStr) = 0 then { no special error handling specified, throw up a dialog and return the error message } begin SendCardMessage(paramPtr, concat('answer "', msgStr, '"')); paramPtr^.returnValue := PasToZero(paramPtr, msgStr); end else if (pos(':', tempStr) > 0) then { requested global AND noDialog so we fill in the global and return empty } begin tempStr := copy(tempStr, pos(':', tempStr) + 1, length(tempStr)); { get the name of the HC global to fill } SetGlobal(paramPtr, tempStr, PasToZero(paramPtr, msgStr)); { and fill it } paramPtr^.returnValue := PasToZero(paramPtr, ''); { return empty } end else { requested noDialog only so we return the error condition as the result } paramPtr^.returnValue := PasToZero(paramPtr, msgStr); end; { procedure } function askedForHelp (paramPtr: XCmdPtr; syntaxMsg: Str255; copyRightMsg: Str255): boolean; { check to see if the user sent a '?' or a '!' as } { the only parameter. if so we will respond with } { the calling syntax or the copyright/version info } { for this external } {} var firstStr: str255; begin askedForHelp := false; if paramPtr^.paramCount = 1 then begin ZeroToPas(paramPtr, paramPtr^.params[1]^, firstStr); { what is the first param? } if firstStr = '?' then begin reportToUser(paramPtr, syntaxMsg); askedForHelp := true end { asked for help } else if firstStr = '!' then begin reportToUser(paramPtr, copyRightMsg); askedForHelp := true end; { asked for copyright info } end; { one parameter passed } end; { function } function PathNameFromDirID (dirID: longint; vRefnum: integer; var fullPathName: str255): OSErr; { build up a full path name given a directory id and an vol ref num. this method isn't reccomended in general (see the } { various tech notes, but we use it in HC externals as HC uses exclusively full path names } var myCPB: CInfoPBRec; directoryName: str255; err: OSErr; begin fullPathName := ''; with myCPB do begin ioNamePtr := @directoryName; ioDrParID := DirId; end; repeat with myCPB do begin ioVRefNum := vRefNum; ioFDirIndex := -1; ioDrDirID := myCPB.ioDrParID; end; err := PBGetCatInfo(@myCPB, FALSE); directoryName := concat(directoryName, ':'); { pascal strings mustn't be longer than 255 chars, though a path name may, so check } if length(directoryName) + length(fullPathName) <= 255 then fullPathName := concat(directoryName, fullPathName) else myCPB.ioDrDirID := fsRtDirID; { lazy persons way to jump out } until (myCPB.ioDrDirID = 2); PathNameFromDirID := err; end; procedure CurrAppPath (paramPtr: XCmdPtr); var FP: FCBPBRec; fileNdx, HCRefNum: integer; filePath, fileName: str255; fileErr: OSErr; dummyH: handle; begin if askedForHelp(paramPtr, 'CurrAppPath(<“noDialog”:errorGlobal>)', 'v1.0, © 1990 Apple Computer, Inc., by Eric Carlson, ') then exit(CurrAppPath); GetAppParms(fileName, HCRefNum, dummyH); { find the resource ref num of the current app - HC I assume } fileName := ''; { now step throught the FCB list looking for HC's entry, the one which matches the res ref num } FP.ioCompletion := nil; { don't want async } FP.ioNamePtr := @fileName; { the file name } FP.ioFCBIndx := 0; { start with the first file } repeat { loop through all files} FP.ioVRefNum := 0; { report all files on every volume, but this field is refilled by each} { PBGet… call so reset it each time} FP.ioFCBIndx := FP.ioFCBIndx + 1; { go to the next file } fileErr := PBGetFCBInfo(@FP, false); until ((fileErr <> noErr) or (FP.ioRefNum = HCRefNum)); filePath := ''; { nothing yet } if ((fileErr = noErr) and (FP.ioRefNum = HCRefNum)) then { found the culprit! } begin fileErr := PathNameFromDirID(FP.ioFCBParID, FP.ioVRefNum, filePath); { build the path } if fileErr = noErr then filePath := concat(filePath, fileName) { add it to the file name } end; if filePath <> '' then { find the name? } paramPtr^.returnValue := PasToZero(paramPtr, filePath) { return it } else ReportToUser(paramPtr, 'Unexpected error.'); { something wrong… } end; { procedure CurrAppPath } procedure MAIN (paramPtr: XCmdPtr); begin CurrAppPath(paramPtr); end; end. { unit OpenFiles}